Use the drag-and-drop manipulator to enable users to drag and drop nodes in your Kanzi application. See Enabling the drag-and-drop gesture for a node.
Use the Drag and Drop Manipulator triggers to react to the drag-and-drop gesture. For example, you can set the appearance of a node when the user drags and drops that node. See Using the Drag and Drop Manipulator triggers.
The drag-and-drop manipulator is one of the input manipulators you can use to add gesture recognition to nodes in your Kanzi application. You can assign the input manipulators through the Kanzi Engine API. See Using input manipulators.
To enable the drag-and-drop gesture for a node:



# sign followed by the name of the alias.


private:
// Handler for the DragAndDropManipulator::StartedMessage message from 2D nodes
// that have an input manipulator which generates drag-and-drop messages.
// This prepares the 2D node for dragging.
void onDragStarted(DragAndDropManipulator::StartedMessageArguments& messageArguments)
{
// Get from the message arguments the node that the user drags.
Node2DSharedPtr dragAndDropNode = dynamic_pointer_cast<Node2D>(messageArguments.getSource());
if (!dragAndDropNode)
{
return;
}
// Save the point from which the user started dragging the node,
// relative to the origin (by default the top left corner) of the node.
m_dragGrabOffset = messageArguments.getPoint();
// When starting a drag-and-drop gesture on the node, bring the node to front.
dragAndDropNode->moveToFront();
}
// Handler for the DragAndDropManipulator::MovedMessage message from 2D nodes
// that have an input manipulator which generates drag-and-drop messages.
// This translates (moves) the node by the distance the user drags it.
void onDragMoved(DragAndDropManipulator::MovedMessageArguments& messageArguments)
{
// Get from the message arguments the node that the user drags.
Node2DSharedPtr dragAndDropNode = dynamic_pointer_cast<Node2D>(messageArguments.getSource());
if (!dragAndDropNode)
{
return;
}
// Move the node by traveled distance given by getPoint, relative to the origin of the node.
// To keep dragging from the same point on the node, subtract the grab offset.
SRTValue2D transform = dragAndDropNode->getLayoutTransformation();
transform.translate(messageArguments.getPoint() - m_dragGrabOffset);
dragAndDropNode->setLayoutTransformation(transform);
}
// Offset from the top left corner of the DragAndDropNode where the user pressed down or clicked on it.
Vector2 m_dragGrabOffset;onProjectLoaded() function create a DragAndDropManipulator and subscribe to its messages.
virtual void onProjectLoaded() KZ_OVERRIDE
{
ScreenSharedPtr screen = getScreen();
Domain* domain = getDomain();
// Get the DragAndDropNode using its alias.
NodeSharedPtr dragAndDropNode = screen->lookupNode<Node>("#DragAndDropNode");
// Create an input manipulator that generates drag-and-drop messages.
DragAndDropManipulatorSharedPtr nodeDragAndDropManipulator = DragAndDropManipulator::create(domain);
// Add the input manipulator to the DragAndDropNode.
dragAndDropNode->addInputManipulator(nodeDragAndDropManipulator);
// Set the duration of the long press before the drag-and-drop starts to 200 ms. The default is 500 ms.
// This is the amount of time the user has to press the node before they can start dragging it.
nodeDragAndDropManipulator->setPressDuration(chrono::milliseconds(200));
// Subscribe to the DragAndDropManipulator::StartedMessage message at the DragAndDropNode node.
// The DragAndDropManipulator generates this message when the user has pressed the node
// for the duration set by DragAndDropManipulator::setPressDuration.
dragAndDropNode->addMessageHandler(DragAndDropManipulator::StartedMessage, bind(&MyProject::onDragStarted, this, placeholders::_1));
// Subscribe to the DragAndDropManipulator::MovedMessage message at the DragAndDropNode node.
// The DragAndDropManipulator generates this message when the finger or mouse moves.
dragAndDropNode->addMessageHandler(DragAndDropManipulator::MovedMessage, bind(&MyProject::onDragMoved, this, placeholders::_1));
}Use the Drag and Drop Manipulator triggers to react to the drag-and-drop gesture. For example, you can set the appearance of a node when the user drags and drops that node.
The Drag and Drop Manipulator has these triggers:
To use the Drag and Drop Manipulator triggers:



For details, see the DragAndDropManipulator class in the API reference.